package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 * 双指针方法
 *
 * @author yulongTian
 * @create 2024-05-25 14:13
 */
public class Test05 {
    public static void main(String[] args) {
        System.out.println(maxArea(new int[]{1, 0, 6, 2, 5, 4, 8, 3, 7}));
//        System.out.println(maxArea(new int[]{2, 3, 10, 5, 7, 8, 9}));
    }

    public static int maxArea(int[] height) {
        int res = 0;
        int leftPoint = 0;
        int rightPoint = height.length - 1;
        while (leftPoint < rightPoint) {
            res = Math.max(res, Math.min(height[leftPoint], height[rightPoint]) * (rightPoint - leftPoint));
            if (height[leftPoint] <= height[rightPoint]) {
                leftPoint++;
            } else {
                rightPoint--;
            }
        }
        return res;
    }
}
